﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iLangl.Transport.Communication
{
	public class ActionResultResponseContext : BaseResponseContext
	{
		protected ActionResult _actionResult = null;
		public override void SetContext(object context)
		{
			try
			{
				base.SetContext(context);

				XmlNode node = document.SelectSingleNode("//ActionResult");
				

				if (node == null)
					return;

				_actionResult = new ActionResult();

				ParseExtendedInfo(node, _actionResult);

				XmlNode resultValuesNode = node.SelectSingleNode("//ResultValues");


				if (resultValuesNode != null)
				{
					foreach (XmlNode childnode in resultValuesNode.ChildNodes)
					{
						_actionResult.ResultValues[childnode.Name] = childnode.InnerText;
					}
				}
				ErrorsResponseContext errorResponseContext = new ErrorsResponseContext();
				errorResponseContext.SetContext(node);
				_actionResult.Errors = (IList<IError>)errorResponseContext.GetContext();
			}
			finally
			{
				FireChanges();
			}
		}

		public override object GetContext()
		{
			return _actionResult;
		}
	}
}
